var my_vue;
$(function() {
	var fromSpace= isEmpty(parseQueryString().fromSpace) ? '0' : parseQueryString().fromSpace;
	var fromGuide= isEmpty(parseQueryString().fromGuide) ? '0' : parseQueryString().fromGuide;
	var fromWhere = isEmpty(parseQueryString().fromWhere) ? '' : parseQueryString().fromWhere;
	var code= parseQueryString().itemsId;
	var userType = parseQueryString().userType;
	my_vue = new Vue({
		el: '#vue_info',
		data: {
			type: isEmpty(parseQueryString().type) ? 'dept' : parseQueryString().type,
			dto: {
				userId: '',
				mobile: '',
				name: '测试用户',
				sex: '男',
				nation: '汉',
				birthday: '1991年12月12日',
				address: '苏州市高大上',
				cardNum: '340825190001233454',
				issued: '苏州市公安局',
				life: '2012.03.28-2022.03.28'
			},
			isHasSfz:false
		},
		methods: {
			simulateUserDto: function() {
				$.ajax({
					type: "post",
					url: gover.saveUserInfo,
					async: true,
					dataType: 'json',
					data: {
						name: this.dto.name,
						sex: this.dto.sex,
						nation: this.dto.nation,
						birthday: this.dto.birthday,
						address: this.dto.address,
						cardNum: this.dto.cardNum,
						issued: this.dto.issued,
						life: this.dto.life
					},
					success: function(result) {
						if(result.success) {
							console.log(result.data.userId);
							my_vue.dto.userId = result.data.userId;
							my_vue.dto.mobile = result.data.mobile;
							sessionStorage.setItem("dto", toJson(my_vue.dto));
							window.location = "userInfo.html?type="+my_vue.type
							+"&fromSpace="+fromSpace
							+"&fromGuide="+fromGuide
							+"&userType="+userType
							+"&code="+code+"&fromWhere="+fromWhere;

						} else {
							showRedMsg("message", "服务器正忙,请稍候重试");
						}

					},
					error: function(result) {
						showRedMsg("message", "服务器正忙,请稍候重试");
						console.log('保存接口失败:' + toJson(result));
					}
				});
			}
		},
		ready: function() {
			//初始化获得总页面数和列表数据
			$("#left").load("../common/gover-left.html");
			this.isHasSfz = isHasSfz;
			getData();
			//上屏
			var url="../up/readIdentityCard.html";
			windowOpen(url);
		}
	});
});

//获取身份证信息
function getData() {
	$.ajax({
		url : device.IdCard,
		async : true,
		type : 'get',
		dataType : 'json',
		success : function(result) {
			if (result.success == true) {
				if(result.data !=''){
						$(".id-tip").html("身份证信息正在读取中<br/>请等待");
						var keyValue = result.data.rawData.split("|");
							var name = keyValue[0];
							var sex = keyValue[1];
							var cardNum = keyValue[5];
							var address = keyValue[4];
							my_vue.dto.name = keyValue[0];
							my_vue.dto.sex=keyValue[1];
							my_vue.dto.nation=keyValue[2];
							my_vue.dto.birthday=keyValue[3].substring(0,4)+"年"+keyValue[3].substring(4,6)+"月"+keyValue[3].substring(6,8)+"日";
							my_vue.dto.address=keyValue[4];
							my_vue.dto.cardNum=keyValue[5];
							my_vue.dto.issued=keyValue[6];
							my_vue.dto.life=keyValue[7].substring(0,4)+"."+keyValue[7].substring(4,6)+"."+keyValue[7].substring(6,8)
							+"-"+keyValue[8].substring(0,4)+"."+keyValue[8].substring(4,6)+"."+keyValue[8].substring(6,8);
							my_vue.simulateUserDto();
				} else{
					window.setTimeout('getData()', 1000);
				}
			} else {
				showRedMsg('', result.message);
				window.setTimeout('getData()', 1000);
			}
		},
		error : function() {
			showRedMsg('','身份证读取失败，请稍后重试');
			return false;
		}
	});
}